#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=1100;
long long n,k;
long long kdsp[maxn];
long long kdnum[maxn];
bool check(long long num)
{
	long long  sum = k;
	for(int i = 1;i<=n;i++)
	{
		if(kdnum[i]<kdsp[i]*num)
		{
			sum -= (kdsp[i]*num-kdnum[i]);
		}
		if(sum<0) return 0;
	}
	return 1;
}
int main()
{
	long long t;
	scanf("%I64d",&t);
	while(t--)
	{
		scanf("%I64d %I64d",&n,&k);
		for(int i = 1;i<=n;i++) scanf("%I64d",&kdsp[i]);
		for(int i = 1;i<=n;i++) scanf("%I64d",&kdnum[i]);
		long long l = 0;
		long long r = 2e9+10;
		long long mid = 0;
		while(l<r)
		{
			mid = (l+r)>>1;
			if(check(mid)) l = mid+1;
			else r = mid-1;
		}
		if(!check(l)) l--;
		printf("%I64d\n",l);
		
	}
} 
